package logic

import (
	"context"
	"srv/shenzhou"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListGoodsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewListGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListGoodsLogic {
	return &ListGoodsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ListGoodsLogic) ListGoods(req *types.ListGoodsRequest) (resp *types.Response, err error) {
	res, err := l.svcCtx.ShenZhouSrv.ListGoods(l.ctx, &shenzhou.ListGoodsRequest{
		Page:     int64(req.Page),
		PageSize: int64(req.PageSize),
	})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  "获取商品列表失败",
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: 200,
		Msg:  "获取商品列表成功",
		Data: map[string]interface{}{
			"list": res.GoodsList,
		},
	}, nil
}
